import { ADDDOCTOR,DELDOCTOR } from '../constant'
import {nanoid} from 'nanoid'

// 初始化数据

const initState = []
const titles=['主任', '副主任', '主治医师', '副主治医师', '实习医生']
const offices=['骨科', '内科', '外科', '妇科', '儿科', '脑科']
for (let i = 0; i < 100; i++) {
    initState.push({
        key: nanoid(),
        name: `李鹏${i}`,
        tel: 13000000000 + parseInt(Math.random() * 1000000000),
        title: titles[parseInt(Math.random() * 5)],
        office: offices[parseInt(Math.random() * 6)],
        condition: Boolean(parseInt(Math.random() * 2)),
        skilled: '',
        brief: ''
    });
}

export default function addReducer(preState = initState, action) {
    // console.log('正在操作reduse...');
    const { type, data } = action
    switch (type) {
        case ADDDOCTOR: return [data, ...preState]
        case DELDOCTOR: return preState.filter(item=>{
            return item.key !==data
        })
        default: return preState
    }
}